Improve UPnP configuration flow#34737
Conversation
| @property | ||
| def unique_id(self) -> str: | ||
| """Get the unique id.""" | ||
| return f"{self.udn}::{self.device_type}" |
There was a problem hiding this comment.
This is confusing. The SSDP protocol provides a USN (UDN and ST combined.) E.g., a search-response is something like (converted to JSON, as the CLI for async_upnp_client presents it like so, keys prefixes with _ added by library):
{"Cache-Control": "max-age=1900", "Location": "http://192.168.178.1:80/RootDevice.xml", "Server": "UPnP/1.0 UPnP/1.0 UPnP-Device-Host/1.0", "ST": "urn:schemas-upnp-org:device:InternetGatewayDevice:1", "USN": "uuid:upnp-InternetGatewayDevice-1_0-889ffacb9043::urn:schemas-upnp-org:device:InternetGatewayDevice:1", "EXT": "", "_timestamp": "2020-04-27 21:33:01.811349", "_address": "192.168.178.1:1900", "_udn": "uuid:upnp-InternetGatewayDevice-1_0-889ffacb9043", "_source": "search"}
The UPnP XML description provides a UDN and a deviceType (together these form the USN from the SSDP protocol), e.g.:
<?xml version="1.0" encoding="utf-8"?>
<root xmlns="urn:schemas-upnp-org:device-1-0">
...
<device>
<deviceType>urn:schemas-upnp-org:device:InternetGatewayDevice:1</deviceType>
<UDN>uuid:upnp-InternetGatewayDevice-1_0-889ffacb9043</UDN>
...
</device>
</root>
Some criticism from my side: The SSDP component in hass returns the XML (in dict form), but entirely discards the search-information. Can be easily worked around, but requires a bit of additional work.
There was a problem hiding this comment.
Ok.
Feel free to update the SSDP integration 👍 (although we use netdisco for ssdp scan, which has been deprecated…)
There was a problem hiding this comment.
I couldn't find the required information in the current implementation. It probably requires a change to netdisco.
What do you propose to do with SSDP, rewrite it to drop netdisco? Should it use its own search implementation or use a library for this? (async_upnp_client provides this, which is what the upnp component uses.) Also, devices also send out advertisements via SSDP, which home assistant could use to passively listen for, instead of 'actively' searching for devices.
There was a problem hiding this comment.
Yeah, async_upnp_client and passive event listening sound good 👍 netdisco has been deprecated and should be dropped.
|
So it seems like this fixes an issue in the beta that upnp config flows cannot be ignored. However this is quite a change and the release is already on Wednesday. We should remove ssdp discovery for the upnp integration in 0.109 so that we can add this feature in 0.110 without having to do major changes last-minute which won't be able to be tested properly. |
Agreed. |
|
Also, I would like to simplify this component by the following things:
This is, of course, a regression wrt features it provides! @balloob @dgomes Is this acceptable? If so, I'll make a separate pull request for this. |
|
I agree. |
d8c7b3c to
27055c1
Compare
|
Please don't merge yet, I think hass can lock up when |
5b9a317 to
a39a3e1
Compare
|
Alright, @balloob, care for another review? |
|
I cannot reproduce the failures from the unit tests. Also, I think the failures are incorrect. One of the tests fails with: The part before the error does await the future (config_flow.py:114): The test also provides a mocked co-rountine for this. Python37 runs without problems. Locally, running python 3.8.0 runs without any problems. CI seems to be using python 3.8.2, which fails. Unsure what to do here. |
|
It's because we use |
|
Thank you for fixing and merging, @balloob! |
|
home-assistant/home-assistant.io#13180 (docs) can be merged as wel, after a review. |
| "init": { | ||
| }, | ||
| "ssdp_confirm": { | ||
| "description": "Do you want to set up this UPnP/IGD device?" |
There was a problem hiding this comment.
One thing that I was thinking last night is that most people don't know what UPnP/IGD is, or how it comes that Home Assistant discovers one. I think that we might want to extend this description to explain what it is/what it can be used for. What do you think ?
There was a problem hiding this comment.
Agreed. Perhaps something like:
A router has been discovered in your network. You can monitor the traffic statistics for this device. Do you want to set up this integration?
There was a problem hiding this comment.
Be aware though: Some other devices also provide information via UPnP/IGD profile, such as access points.
Breaking change
Proposed change
Improvements to the configuration flow by using a custom flow:
Type of change
Example entry for
configuration.yaml:# Example configuration.yamlAdditional information
Checklist
black --fast homeassistant tests)If user exposed functionality or configuration variables are added/changed:
If the code communicates with devices, web services, or third-party tools:
Updated and included derived files by running:
python3 -m script.hassfest.requirements_all.txt.Updated by running
python3 -m script.gen_requirements_all..coveragerc.The integration reached or maintains the following Integration Quality Scale: